/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package asfabdesk.dominio;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;

/**
 *
 * @author marco.machado
 */
@Entity
@NamedQueries(value = {
    @NamedQuery(name = "SaidasPorSituacao", query = "SELECT s FROM SaidaFinanceira s WHERE dataSaida BETWEEN (?) AND (?) and situacao=? "),
    @NamedQuery(name = "SaidasPorSituacaoAmbas", query = "SELECT s FROM SaidaFinanceira s WHERE dataSaida BETWEEN (?) AND (?) and situacao=1 OR situacao=2 "),
    @NamedQuery(name = "SaidasPorSituacaoDeposito", query = "SELECT s FROM SaidaFinanceira s WHERE dataSaida BETWEEN (?) AND (?) and situacao=? and tipoSaida.depositoFinanceiro= ? "),
    @NamedQuery(name = "SaidasPorSituacaoAmbasDeposito", query = "SELECT s FROM SaidaFinanceira s WHERE dataSaida BETWEEN (?) AND (?) and situacao=1 OR situacao=2 and tipoSaida.depositoFinanceiro= ? "),
    @NamedQuery(name = "SaidasPorSituacaoTipoSaida", query = "SELECT s FROM SaidaFinanceira s WHERE dataSaida BETWEEN (?) AND (?) and situacao=? and tipoSaida= ? "),
    @NamedQuery(name = "SaidasPorSituacaoAmbasTipoSaida", query = "SELECT s FROM SaidaFinanceira s WHERE dataSaida BETWEEN (?) AND (?) and situacao=1 OR situacao=2 and tipoSaida= ? ")
//    @NamedQuery(name = "SaidasPorSituacaoCentro", query = "SELECT s FROM SaidaFinanceira s WHERE dataSaida BETWEEN (?) AND (?) and situacao=? and convenio= ? "),
//    @NamedQuery(name = "SaidasPorSituacaoAmbasCentro", query = "SELECT s FROM SaidaFinanceira s WHERE dataSaida BETWEEN (?) AND (?) and situacao=1 OR situacao=2 and convenio= ? ")
})
@SequenceGenerator(name = "SAIDA_SEQ", sequenceName = "saida_id_saidaa_seq", allocationSize = 1)
public class SaidaFinanceira implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE,generator="SAIDA_SEQ")
    private Long id;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataLancamento;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataConfirmacao;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataSaida;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataEstorno;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataCancelamento;
    private double valorTotal;
    private double fundoDepPre; // valor do Fundo do depósito Pré- Saída
    private double fundoDepPos;//  valor do Fundo do depósito Pós- Saída
    private String observacao;
    private int situacao; //0= cancelada , 1= lançada, 2= confirmada
    @JoinColumn(name = "TIPO_SAIDA", referencedColumnName = "id")
    @ManyToOne
    private TipoSaida tipoSaida;
    @JoinColumn(name = "ITENS_SAIDA", referencedColumnName = "id")
    @OneToMany
    private List<ItemSaida> itens = new ArrayList(); // detalhamento da saida
//    @JoinColumn(name = "USUARIOS", referencedColumnName = "id")
    @ManyToOne
    private Usuario usuarioLancamento; // funcionario ASFAB
//    @JoinColumn(name = "USUARIOS", referencedColumnName = "id")
    @ManyToOne
    private Usuario usuarioConfirmacao; // funcionario ASFAB
//    @JoinColumn(name = "USUARIOS", referencedColumnName = "id")
    @ManyToOne
    private Usuario usuarioCancelamento; // funcionario ASFAB
    @ManyToOne
    private Usuario usuarioEstorno; // funcionario ASFAB

    public Long getId() {
        return id;
    }

    public Date getDataConfirmacao() {
        return dataConfirmacao;
    }

    public void setDataConfirmacao(Date dataConfirmacao) {
        this.dataConfirmacao = dataConfirmacao;
    }

    public Date getDataSaida() {
        return dataSaida;
    }

    public void setDataSaida(Date dataEntrada) {
        this.dataSaida = dataEntrada;
    }

    public Date getDataLancamento() {
        return dataLancamento;
    }

    public void setDataLancamento(Date dataLancamento) {
        this.dataLancamento = dataLancamento;
    }

    public double getFundoDepPos() {
        return fundoDepPos;
    }

    public void setFundoDepPos(double fundoDepPos) {
        this.fundoDepPos = fundoDepPos;
    }

    public double getFundoDepPre() {
        return fundoDepPre;
    }

    public void setFundoDepPre(double fundoDepPre) {
        this.fundoDepPre = fundoDepPre;
    }

    public List<ItemSaida> getItens() {
        return itens;
    }

    public void setItens(List<ItemSaida> itens) {
        this.itens = itens;
    }

    public String getObservacao() {
        return observacao;
    }

    public void setObservacao(String observacao) {
        this.observacao = observacao;
    }

    public int getSituacao() {
        return situacao;
    }

    public void setSituacao(int situacao) {
        this.situacao = situacao;
    }

    public TipoSaida getTipoSaida() {
        return tipoSaida;
    }

    public void setTipoSaida(TipoSaida tipoSaida) {
        this.tipoSaida = tipoSaida;
    }

    public double getValorTotal() {
        return valorTotal;
    }

    public void setValorTotal(double valorTotal) {
        this.valorTotal = valorTotal;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Usuario getUsuarioCancelamento() {
        return usuarioCancelamento;
    }

    public void setUsuarioCancelamento(Usuario usuarioCancelamento) {
        this.usuarioCancelamento = usuarioCancelamento;
    }

    public Usuario getUsuarioConfirmacao() {
        return usuarioConfirmacao;
    }

    public void setUsuarioConfirmacao(Usuario usuarioConfirmacao) {
        this.usuarioConfirmacao = usuarioConfirmacao;
    }

    public Usuario getUsuarioLancamento() {
        return usuarioLancamento;
    }

    public void setUsuarioLancamento(Usuario usuarioLancamento) {
        this.usuarioLancamento = usuarioLancamento;
    }

    public Date getDataEstorno() {
        return dataEstorno;
    }

    public void setDataEstorno(Date dataEstorno) {
        this.dataEstorno = dataEstorno;
    }

    public Usuario getUsuarioEstorno() {
        return usuarioEstorno;
    }

    public void setUsuarioEstorno(Usuario usuarioEstorno) {
        this.usuarioEstorno = usuarioEstorno;
    }

    public Date getDataCancelamento() {
        return dataCancelamento;
    }

    public void setDataCancelamento(Date dataCancelamento) {
        this.dataCancelamento = dataCancelamento;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SaidaFinanceira)) {
            return false;
        }
        SaidaFinanceira other = (SaidaFinanceira) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "asfabdesk.dominio.SaidaFinanceira[id=" + id + "]";
    }
}
